// index.js
// 获取应用实例
const app = getApp()
// let sum=0;
let sum=0;
Page({
  onReady:function(){
    this.audioCtx = wx.createInnerAudioContext();
    this.audioCtx.src='../../sound.wav'
    this.audioCtx.volume=1
    this.audioCtx.play()
  },
  data: {
    width:'',
    height:'',
    img1:'bottle_1.png',
    img2:'bottle_1.png',
    img3:'bottle_1.png',
    img4:'bottle_1.png',

    leftLooks1: '8',
    topLooks1: '54',
    leftLooks2: '20',
    topLooks2: '54',
    leftLooks3: '30',
    topLooks3: '54',
    leftLooks4: '40',
    topLooks4: '54',


  },
imagetouchmove1:function(e){
    var self = this;
    // console.log(e.touches[0])
    self.setData({
      leftLooks1: (e.touches[0].clientX)/(this.data.width)*100 ,
      topLooks1: (e.touches[0].clientY)/(this.data.height)*100
    })
  },
  imagetouchmove2:function(e){
    var self = this;
    self.setData({
      leftLooks2: (e.touches[0].clientX)/(this.data.width)*100 ,
      topLooks2: (e.touches[0].clientY)/(this.data.height)*100
    })
  },
  imagetouchmove3:function(e){
    var self = this;
    self.setData({
      leftLooks3: (e.touches[0].clientX)/(this.data.width)*100 ,
      topLooks3: (e.touches[0].clientY)/(this.data.height)*100
    })
  },
  imagetouchmove4:function(e){
    var self = this;
    console.log(e.touches[0])

    wx.getSystemInfo({
      success: (res) => {
        // console.log(res.screenWidth)
        this.setData({
          width:res.screenWidth,
          height:res.screenHeight
        })
      },
    })
    self.setData({
      leftLooks4: (e.touches[0].clientX)/(this.data.width)*100 ,
      topLooks4: (e.touches[0].clientY)/(this.data.height)*100
    })

  },
  //结束事件
  end1:function(){
    var that=this;
    console.log(sum)
    this.setData({
      img1:'break.png'
    })
    sum++;
    if(sum==4){
      // console.log(sum)
      that.onShow()
      that.refresh()
      console.log(sum)
     
    }

  },
  end2:function(){
    var that=this;
    this.setData({
      img2:'break.png'
    })
    sum++;
    if(sum==4){
      // console.log(sum)
      that.onShow()
      that.refresh()
      console.log(sum)
      // getCurrentPages()[getCurrentPages().length - 1].onLoad()
    }
    // console.log(sum)
  },
  end3:function(){
    var that=this;
    // console.log(2)
    this.setData({

      img3:'break.png'
    })
    sum++
    if(sum==4){
      // console.log(sum)
      that.onShow()
      that.refresh()
      console.log(sum)
      // getCurrentPages()[getCurrentPages().length - 1].onLoad()
    }
  },
  end4:function(){
     var that=this;
    // console.log(2)
    this.setData({

      img4:'break.png'
    })
    sum++
    if(sum==4){
      // console.log(sum)
      that.onShow()
      that.refresh()
      console.log(sum)
      // getCurrentPages()[getCurrentPages().length - 1].onLoad()
    }
  },
  refresh:function(){
    sum=0;
    this.setData({


      leftLooks1: '8',
      topLooks1: '54',
      leftLooks2: '20',
      topLooks2: '54',
      leftLooks3: '30',
      topLooks3: '54',
      leftLooks4: '40',
      topLooks4: '54',
    })
  },

  onShow:function(){
    // console.log(sum)

    var num=wx.getStorageSync('number');
    // console.log(num)

    switch (num){
      case '1':
        this.setData({
          img1:'bottle_1.png',
          img2:'bottle_1.png',
          img3:'bottle_1.png',
          img4:'bottle_1.png',
        })
      
        break;

        case '2':
          this.setData({
            img1:'bottle_2.png',
            img2:'bottle_2.png',
            img3:'bottle_2.png',
            img4:'bottle_2.png',
          })
        
          break;

        case '3':
          this.setData({
            img1:'bottle_4.png',
            img2:'bottle_4.png',
            img3:'bottle_4.png',
            img4:'bottle_4.png',
          })
        
          break;
        
        case '4':
          this.setData({
            img1:'bottle4.png',
            img2:'bottle4.png',
            img3:'bottle4.png',
            img4:'bottle4.png',
          })
        
          break;
          
        case '5':
          this.setData({
            img1:'bottle5.png',
            img2:'bottle5.png',
            img3:'bottle5.png',
            img4:'bottle5.png',
          })
        
          break;
          case '6':
          this.setData({
            img1:'bottle6.png',
            img2:'bottle6.png',
            img3:'bottle6.png',
            img4:'bottle6.png',

          })
        
          break;
          case '7':
            this.setData({
              img1:'bottle7.png',
              img2:'bottle7.png',
              img3:'bottle7.png',
              img4:'bottle7.png',
            })
          
            break;
            case '8':
              this.setData({
                img1:'bottle8.png',
                img2:'bottle8.png',
                img3:'bottle8.png',
                img4:'bottle8.png',
              })
            
              break;
              case '9':
                this.setData({
                  img1:'bottle9.png',
                  img2:'bottle9.png',
                  img3:'bottle9.png',
                  img4:'bottle9.png',
                })
              
                break;  
            default:
                break;
    
    }
  },

 
  goCollect:function(e){

    var num=wx.getStorageSync('number');
    console.log(num)
    if(num==1){
      this.setData({
        img:'bottle_3.png'
      })
    }

    wx.navigateTo({
      
      url: '/pages/style/style',
    })
  }


})
